package code_rhapsody.stack_queue;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @author Synhard
 * @version 1.0
 * @class Code1
 * @description TODO
 * @tel 13001321080
 * @email 823436512@qq.com
 * @date 2021-07-31 14:49
 */
public class Code1 {
    public static void main(String[] args) {

    }
}

class MyQueue {

    private Deque<Integer> stack1; // main stack
    private Deque<Integer> stack2; // assist stack

    /** Initialize your data structure here. */
    public MyQueue() {
        stack1 = new LinkedList<>();
        stack2 = new LinkedList<>();
    }

    /** Push element x to the back of queue. */
    public void push(int x) {
        stack1.addLast(x);
    }

    /** Removes the element from in front of queue and returns that element. */
    public int pop() {
        while (!stack1.isEmpty()) {
            stack2.addLast(stack1.removeLast());
        }
        int res = stack2.removeLast();
        while (!stack2.isEmpty()) {
            stack1.addLast(stack2.removeLast());
        }
        return res;
    }

    /** Get the front element. */
    public int peek() {
        while (!stack1.isEmpty()) {
            stack2.addLast(stack1.removeLast());
        }
        int res = stack2.peekLast();
        while (!stack2.isEmpty()) {
            stack1.addLast(stack2.removeLast());
        }
        return res;
    }

    /** Returns whether the queue is empty. */
    public boolean empty() {
        return stack1.isEmpty();
    }
}